﻿using DevExpress.XtraEditors.Controls;
using EkStudio.com.bean.xml.BillModule;
using EkStudio.com.bean.xml.RootInterface.DataSource;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace EkStudio.com.ui.form.Auto
{
    public partial class AutoQueryCheckForm : DevExpress.XtraEditors.XtraForm
    {

        private ProjectRootPanel RootPanel = null;

        private BillModuleItem bean = null;

        private AutoQueryFormula QForm = null;

        private List<string> checkList = new List<string>();

        public AutoQueryCheckForm(BillModuleItem bill,ProjectRootPanel Root,AutoQueryFormula form)
        {
            InitializeComponent();
            this.RootPanel = Root;
            this.bean = bill;
            QForm = form;
            this.InitForm();
        }

        private void InitForm()
        {
            BillListBox.Items.Clear();
            if (bean.DataSource != null && bean.DataSource.TableItems != null && bean.DataSource.TableItems.Count > 0)
            {
                foreach (BillSourceTabItems source in bean.DataSource.TableItems)
                {
                    CheckedListBoxItem item = new CheckedListBoxItem(bean.getKey(), source.Caption);
                    BillListBox.Items.Add(item);
                }
                
            }
        }

        private void BtnSubmit_Click(object sender, EventArgs e)
        {
            checkList.Clear();
            if (BillListBox.Items.Count > 0)
            {
                foreach(CheckedListBoxItem item in BillListBox.Items)
                {
                    if(item.CheckState == CheckState.Checked)
                    {
                        checkList.Add(item.Description);
                    }
                }
            }
        }


        private bool isMouseDown = false;
        private Point FormLocation;     //form的location
        private Point mouseOffset;      //鼠标的按下位置

        public List<string> CheckList
        {
            get
            {
                return checkList;
            }

            set
            {
                checkList = value;
            }
        }

        private void BoxPanel_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                isMouseDown = true;
                FormLocation = this.Location;
                mouseOffset = Control.MousePosition;
            }
        }

        private void BoxPanel_MouseMove(object sender, MouseEventArgs e)
        {
            int _x = 0;
            int _y = 0;
            if (isMouseDown)
            {
                Point pt = Control.MousePosition;
                _x = mouseOffset.X - pt.X;
                _y = mouseOffset.Y - pt.Y;

                this.Location = new Point(FormLocation.X - _x, FormLocation.Y - _y);
            }
        }

        private void BoxPanel_MouseUp(object sender, MouseEventArgs e)
        {
            isMouseDown = false;
        }
    }
}